#include "Array3D.h"

CArray3D::CArray3D(int im, int jm, int km)
: imax(im), jmax(jm), kmax(km)
{
	if (imax<=0 || jmax<=0 || kmax<=0)
		throw BadSize();

	arr3D = new int**[imax];
	
	for(int i=0; i<imax; i++)
	{
		arr3D[i] = new int*[jmax];
		for(int j=0; j<jmax; j++)
			arr3D[i][j] = new int[kmax];
	}
}

CArray3D::~CArray3D(void)
{
	for(int i=0; i<imax; i++)
	{
		for(int j=0; j<jmax; j++)
			delete [] arr3D[i][j];
		delete [] arr3D[i];
	}
	delete [] arr3D;
}

int& CArray3D::operator() (int i, int j, int k)
{
	if (i>=imax || j>=jmax || k>=kmax || i<0 || j<0 || k<0)
	{
		//throw BoundsViolations();			Return empty cell when hero goes out of bounds
		bViol = 32;
		return bViol;
	}
	return arr3D[i][j][k];
}

const int& CArray3D::operator() (int i, int j, int k) const
{
	if (i>=imax || j>=jmax || k>=kmax || i<0 || j<0 || k<0)
	{
		//throw BoundsViolations();		Return empty cell when hero goes out of bounds
		bViol = 32;
		return bViol;
	}
	return arr3D[i][j][k];
}
